jQuery.fn.extend({
	highText : function (searchWords, htmlTag, tagClass) {
		return this.each(function() {
			$(this).html(function high(replaced, search, htmlTag, tagClass) {
				var pattarn = search.replace(/\b(\w+)\b/g, "($1)").replace(/\s+/g, "|");
				
				return replaced.replace(new RegExp(pattarn, "ig"), function(keyword) {
					return $("<" + htmlTag + " class=" + tagClass + ">" + keyword + "</" + htmlTag + ">").outerHTML();
				});
			}($(this).text(), searchWords, htmlTag, tagClass));
		});
	},
	outerHTML : function(s) {
		return (s) ? this.before(s).remove() : jQuery("<p>").append(this.eq(0).clone()).html();
	}
});

if ($.browser.msie && $.browser.version == "6.0" && !$.support.style)
{
	$(document).ready(function () {
  		new DialogBox_show('640', '<p class="p" style="font-size: 14px">你目前使用的浏览器版本过低，将不能使用本站部分功能。请升级你的 <a href="http://windows.microsoft.com/zh-CN/internet-explorer/downloads/ie-8">Internet Explorer 浏览器</a>获取最佳的浏览效果<br /><br /><div align="center"><a href="http://www.google.cn/chrome/eula.html?hl=zh-CN&platform=win" style="font-size: 16px">点击下载谷歌浏览器</a> | <a href="http://windows.microsoft.com/zh-CN/internet-explorer/downloads/ie-8" style="font-size: 16px">点击下载 Internet Explorer 浏览器</a></div></p>', '提示信息', '');
	});
}

// Test:
/*$(document).ready(function () {
	$('.footer a').highText('关于', 'span', 't');
});*/


function qAlert(message, width)
{
  /************************
	  
	  DialogBox_show( boxWidth,html,titleTxt,butTxt )
	  
	  参数说明：
	  1、boxWidth为弹出盒子的宽度，可以设置大小，比如：255，如果不设置则为默认450的宽。
	  2、html可以任意添加代码、样式以及脚本。
	  3、titleTxt为头部的提示信息。
	  4、butTxt为按钮文字。
	  
  ************************/
  var html  = '<p class="p">'+ message +'</p>';
  
  if (!width)
  {
	  width = 255;
  }
  
  new DialogBox_show(width, html, '提示信息', '确定');
}

function ajax_request(url, params)
{	
	if (params)
	{
		$.post(url, params, function (result) {
			if (result.err)
			{
				qAlert(result.err);
			}
			else if (result.rsm && result.rsm.url)
			{
				window.location = decodeURIComponent(result.rsm.url);
			}
			else
			{
				window.location.reload();
			}
		}, 'json').error(function (error) { if ($.trim(error.responseText) != '') { alert('发生错误, 返回的信息: ' + error.responseText); } });
	}
	else
	{
		$.get(url, function (result) {
			if (result.err)
			{
				qAlert(result.err);
			}
			else if (result.rsm && result.rsm.url)
			{
				window.location = decodeURIComponent(result.rsm.url);
			}
			else
			{
				window.location.reload();
			}
		}, 'json').error(function (error) { if ($.trim(error.responseText) != '') { alert('发生错误, 返回的信息: ' + error.responseText); } });
	}
	
	return false;
}

function ajax_post(formEl, processer, fade_alert)	// 表单对象，用 jQuery 获取，回调函数名
{	
	if (typeof(processer) != 'function')
	{
		if (fade_alert)
		{
			processer = _ajax_post_processer_fade;
		}
		else
		{
			processer = _ajax_post_processer_qAlert;
		}
	}
	else
	{
		if (document.getElementById('tip_error_message'))
		{
			$('#tip_error_message').hide();
		}
		
		$('span.err').hide();
	}
	
	formEl.ajaxSubmit({
		dataType:	'json',
		success:	processer,
		error:	function (error) { if ($.trim(error.responseText) != '') { alert('发生错误, 返回的信息: ' + error.responseText); } }
	});
}

function _ajax_post_processer_qAlert(result)
{
	return _ajax_post_processer(result)
}

function _ajax_post_processer_fade(result)
{
	return _ajax_post_processer(result, true)
}

function _ajax_post_processer(result, fade_alert)
{	
	if (typeof(result.errno) == 'undefined')
	{
		if (fade_alert)
		{
			//default_alert(result);
			qAlert(result.err);
		}
		else
		{
			qAlert(result);
		}
	}
	else if (result.errno != 1)
	{
		if (fade_alert)
		{
			//default_alert(result.err);
			qAlert(result.err);
		}
		else
		{
			qAlert(result.err);
		}
	}
	else
	{		
		if (result.rsm && result.rsm.url)
		{
			window.location = decodeURIComponent(result.rsm.url);
		}
		else
		{
			window.location.reload();
		}
	}
}

function _ajax_post_alert_processer(result)
{
	if (typeof(result.errno) == 'undefined')
	{
		alert(result);
	}
	else if (result.errno != 1)
	{
		alert(result.err);
	}
	else
	{
		if (result.rsm && result.rsm.url)
		{
			window.location = decodeURIComponent(result.rsm.url);
		}
		else
		{
			window.location.reload();
		}
	}
}

//自动计算字数
function data_len(data)
{
	var int_length=0;
	for (var i = 0; i < data.length; i++)
	{
   		if ((data.charCodeAt(i) < 0) || (data.charCodeAt(i) > 255))
		{
    		int_length += 2;
		}
		else
    	{
			int_length += 1;
		}
	}
	return int_length;
}

function set_string(str,len)
{
	var strlen = 0; 
	var s = "";
	for(var i = 0;i < str.length;i++)
	{
		if (str.charCodeAt(i) > 128)
		{
			strlen += 2;
		}
		else
		{ 
			strlen++;
		}
		s += str.charAt(i);
		if (strlen >= len)
		{ 
			return s ;
		}
	}
	return s;
}

function focus_question(el, text_el, question_id)
{
	if (el.hasClass('cur'))
	{
		text_el.html('关注');
	}
	else
	{
		text_el.html('取消关注');
	}
	
	el.addClass('load');
	
	$.get(G_BASE_URL + '/question/ajax/focus/question_id-' + question_id, function (data)
	{
		if (data.errno == 1)
		{
			if (data.rsm.type == 'add')
			{
				el.addClass('cur');
			}
			else
			{
				el.removeClass('cur');
			}
		}
		else
		{
			if (data.err)
			{
				qAlert(data.err);
			}
			
			if (data.rsm.url)
			{
				window.location = decodeURIComponent(data.rsm.url);
			}
		}
		
		el.removeClass('load');
	}, 'json');
}

function focus_topic(el, text_el, topic_id)
{
	if (el.hasClass('cur'))
	{
		text_el.html('关注');
	}
	else
	{
		text_el.html('取消关注');
	}
	
	el.addClass('load');
	
	$.get(G_BASE_URL + '/topic/ajax/focus_topic/topic_id-' + topic_id, function (data)
	{
		if (data.errno == 1)
		{
			if (data.rsm.type == 'add')
			{
				el.addClass('cur');
			}
			else
			{
				el.removeClass('cur');
			}
		}
		else
		{
			if (data.err)
			{
				qAlert(data.err);
			}
			
			if (data.rsm.url)
			{
				window.location = decodeURIComponent(data.rsm.url);
			}
		}
		
		el.removeClass('load');
	}, 'json');
}

function follow_people(el, text_el, uid)
{
	if (el.hasClass('cur'))
	{
		text_el.html('关注');
	}
	else
	{
		text_el.html('取消关注');
	}
	
	el.addClass('load');
	
	$.get(G_BASE_URL + '/follow/ajax/follow_people/uid-' + uid, function (data)
	{
		if (data.errno == 1)
		{
			if (data.rsm.type == 'add')
			{
				el.addClass('cur');
			}
			else
			{
				el.removeClass('cur');
			}
		}
		else
		{
			if (data.err)
			{
				qAlert(data.err);
			}
			
			if (data.rsm.url)
			{
				window.location = decodeURIComponent(data.rsm.url);
			}
		}
		
		el.removeClass('load');
	}, 'json');
}

function show_prompt(data, w, h)
{
	return $.fancybox(data, {
		width: w,
		height: h,
		autoSize: false,
		closeClick: false
	});
}

function update_signature(signature)
{
	if (!signature)
	{
		qAlert('请用一句话介绍自己');
		
		return false;
	}
	
	$.post(G_BASE_URL + '/account/ajax/update_signature/', 'signature=' + signature, function (result) {		
		qAlert(result.err);
	}, "json");
}

function push_weibo(array_data)
{
	$.post(G_BASE_URL + '/account/ajax/weibo_push/', array_data, function (result) {			
		alert(result.err);
		
		if (result.errno == 1)
		{
			window.location.reload();
		}
	}, "json");
}

//页面统计获取数据
function check_notifications() {
	if (G_USER_ID == 0)
	{
		return false;
	}
		
	$.get(G_BASE_URL + '/home/ajax/notifications/', function (result) {
		if (Number(result.rsm.notifications_num) > 0)
		{
			$('#notifications_num').removeClass('hide').html(result.rsm.notifications_num);
				
			if ($("#notitile_all").length > 0)
			{
				$("#notitile_all").fadeIn();
				$('#announce_num').html(result.rsm.notifications_num);
			
				$.get(G_BASE_URL + '/notifications/ajax/list/flag-1__page-0', function (response)
				{
					if (response.length)
					{
						$("#notification_list").html(response);
						
						notification_show(5)
					}
				});
			}
		}
		else
		{
			$('#notifications_num').addClass('hide');

			if ($('#notitile_all').length > 0)
			{
				$('#notitile_all').hide();
			}

			if (('#tab_all_notifications').length > 0)
			{
				$('#tab_all_notifications').click();
			}
		}

		if (Number(result.rsm.inbox_num) > 0)
		{
			$('#inbox_num').show();
			$('#inbox_num').html(result.rsm.inbox_num);
		}
		else
		{
			$('#inbox_num').hide();
		}
	}, 'json');
}

function mark_notifications(notification_id, reload)
{
	if (notification_id)
	{
		$("#notification_" + notification_id).remove();
		
		if ($("#announce_num").length > 0)
		{
			$("#announce_num").html(String(Number($("#announce_num").html()) - 1));
		}
		
		$("#notifications_num").html(String(Number($("#notifications_num").html()) - 1));
		
		var url = G_BASE_URL + '/notifications/ajax/read_notification/notification_id-' + notification_id + '__read_type-1';
	}
	else
	{
		if ($("#notitile_all"))
		{
			$("#notitile_all").fadeOut();
		}
		
		var url = G_BASE_URL + '/notifications/ajax/read_notification/read_type-0';
	}
	
	$.get(url, function (respose)
	{
		check_notifications();
		notification_show(5);

		if (reload)
		{
			window.location.reload();
		}
	});
}

function notification_show(max)
{
	if ($('#notitile_all').length > 0)
	{
		var n_count = 0;
		
		$("#notification_list").find("li").each(function()
		{
			if (n_count < 5)
			{
				$(this).show();
			}
			else
			{
				$(this).hide();
			}
			n_count ++;
		});
		
		if ($("#notification_list").find("li").size() == 0)
		{
			$('#notitile_all').fadeOut();
		}
	}
}

function ajax_load(url, target)
{
	$(target).html('<p style="padding: 15px 0" align="center"><img src="' + G_STATIC_URL + '/common/loading_b.gif" alt="" /></p>');
	
	$.get(url, function (response)
		{
			if (response.length)
			{
				$(target).html(response);
			}
			else
			{
				$(target).html('<p style="padding: 15px 0" align="center">没有内容</p>');
			}
	});
}

var _bp_more_o_inners = new Array();
var _bp_more_pages = new Array();

function bp_more_load(url, bp_more_o_inner, target_el, start_page, callback_func)
{
	if (!bp_more_o_inner.attr('id'))
	{
		return false;
	}
	
	if (!start_page)
	{
		start_page = 0
	}
	
	_bp_more_pages[bp_more_o_inner.attr('id')] = start_page;
	
	_bp_more_o_inners[bp_more_o_inner.attr('id')] = bp_more_o_inner.html();
	
	bp_more_o_inner.unbind('click');
	
	bp_more_o_inner.bind('click', function () {
		var _this = this;
			
		$(this).addClass('loading');
		
		$(this).find('a').html('正在载入...');
			
		$.get(url + '__page-' + _bp_more_pages[bp_more_o_inner.attr('id')] + '__version-2', function (response)
		{
			if ($.trim(response) != '')
			{
				if (_bp_more_pages[bp_more_o_inner.attr('id')] == start_page)
				{
					target_el.html(response);
				}
				else
				{
					target_el.append(response);
				}
							
				_bp_more_pages[bp_more_o_inner.attr('id')]++; 
				
				$(_this).html(_bp_more_o_inners[bp_more_o_inner.attr('id')]);
			}
			else
			{
				if (_bp_more_pages[bp_more_o_inner.attr('id')] == start_page)
				{
					target_el.html('<p style="padding: 15px 0" align="center">没有内容</p>');
				}
							
				$(_this).addClass('disabled').unbind('click').bind('click', function () { return false; });
						
				$(_this).find('a').html('没有更多了');
			}
				
			$(_this).removeClass('loading');
			
			if (callback_func != null)
			{
				callback_func();
			}
		});
			
		return false;
	});
	
	bp_more_o_inner.click();
}

function content_switcher(hide_el, show_el)
{
	hide_el.hide();
	show_el.fadeIn();
}

function _pm_form_processer(result)
{
	if (result.errno != 1)
	{
		if (typeof(result.rsm.tips_id) != 'undefined')
		{
			if (document.getElementById('tip_' + result.rsm.tips_id))
			{
				$('#tip_' + result.rsm.tips_id).html(result.err).show();
			}
			else
			{
				alert(result.err);
			}
		}
		else
		{
			alert(result.err);
		}
	}
	else
	{
		if (result.rsm)
		{	
			if (result.rsm.url)
			{
				window.location = decodeURIComponent(result.rsm.url);
			}
			else if (result.rsm.element_id)
			{
				//alert(result.err);
			
				$('#' + result.rsm.element_id).fadeOut();
			}
			else if (result.rsm.click_id)
			{
				alert(result.err);
					
				if (window.location.href.indexOf('/inbox/') == -1)
				{
					try {
						document.getElementById(result.rsm.click_id).click();
					}
					catch (e)
					{
						window.location.reload();
					}
				}
				else
				{
					window.location.reload();
				}
			}
			else
			{
				alert(result.err);
			
				window.location.reload();
			}
		}
		else
		{
			alert(result.err);
			
			window.location.reload();
		}
	}
}

function _tips_form_processer(result)
{
	if (typeof(result.errno) == 'undefined')
	{
		alert(result);
	}
	else if (result.errno != 1)
	{		
		if (typeof(result.rsm) == 'undefined')
		{
			if (document.getElementById('tip_error_message'))
			{
				$('#tip_error_message').html(result.err).show();
			}	
			else
			{
				qAlert(result.err);
			}
		}
		else if (result.rsm)
		{	
			var selecter = 'input[name=' + result.rsm.input + '], select[name=' + result.rsm.input + ']';
			
			if (document.getElementById('tip_' + result.rsm.tips_id))
			{
				$('#tip_' + result.rsm.tips_id).html(result.err).show();
			}
			else if ($('#tip_' + $(selecter).attr('id')).attr('id'))
			{
				if (!$('#tip_' + $(selecter).attr('id')).hasClass('default_err') && !$('#tip_' + $(selecter).attr('id')).hasClass('all_err_tips'))
				{
					$('#tip_' + $(selecter).attr('id')).removeClass().addClass('err').html(result.err).show();
				}
				else
				{
					$('#tip_' + $(selecter).attr('id')).html(result.err).show();
				}
			}
			else if (document.getElementById('tip_error_message'))
			{
				$('#tip_error_message').html(result.err).show();
			}		
			else
			{
				qAlert(result.err);
			}
		}
		else
		{
			if (document.getElementById('tip_error_message'))
			{
				$('#tip_error_message').html(result.err).show();
			}	
			else
			{
				qAlert(result.err);
			}
		}
	}
	else
	{
		if (result.rsm && result.rsm.url)
		{
			window.location = decodeURIComponent(result.rsm.url);
		}
		else if (result.err && document.getElementById('tip_success_message'))
		{
			$.scrollTo(0, 800, {queue:true});
			
			$('#tip_success_message').html(result.err).fadeIn();
			
			setTimeout(function () {
				$('#tip_success_message').fadeOut();
			}, 3000);
		}
		else
		{
			window.location.reload();
		}
	}
}

function hightlight(el, class_name)
{
	if (el.hasClass(class_name))
	{
		return true;
	}
	
	//window.scrollTo(0, (el.position()['top'] - 5));
	
	var hightlight_timer_front = setInterval(function () {
		el.addClass(class_name);
	}, 500);
	
	var hightlight_timer_background = setInterval(function () {
		el.removeClass(class_name);
	}, 600);
	
	setTimeout(function () {
		clearInterval(hightlight_timer_front);
		clearInterval(hightlight_timer_background);
		
		el.addClass(class_name);
	}, 1200);
	
	setTimeout(function () {
		el.removeClass(class_name);
	}, 6000);
}

// 回车换成<BR/>
function nl2br(str)
{
	return str.replace(new RegExp("\r\n|\n\r|\r|\n", "g"), "<br />");
}

function strip_tags(input, allowed)
{
    allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('');
    var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
        commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
    return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
    });
} 

var doc = document,_$$$ = function(o){return 'string' == typeof o ? doc.getElementById(o) : o ;};
function DialogBox_show( boxWidth,html,titleTxt,butTxt,fn ){
	
	this[0] = document,_seif= this;
	this.elScroll= 0;
	this.elementsMaskBox = elementsMaskBox;
	this.bd = this[0].getElementsByTagName("body")[0];
	this.eWidth = 450; //默认弹出框宽度
	var locaHref = window.location.href;
	
	//首次登录弹框处理
	if(locaHref.indexOf('first_login') > 0){
		this.addLoadEvent(function(){
			_seif.elScroll = document.documentElement.scrollHeight || document.body.scrollHeight; 
			_seif.add_mask();
		});	
	}else{
		this.elScroll = document.documentElement.scrollHeight || document.body.scrollHeight; 
		this.add_mask();	
	}
	
	this.info( boxWidth,html,titleTxt,butTxt );
	if (fn!=null){fn();}
};
DialogBox_show.prototype.addLoadEvent= function(f) {
  var ol = window.onload;
  if(typeof window.onload != 'function'){
    window.onload = f;
  }else{
    window.onload = function(){
      if(ol){
        ol();
      }
      f();
    }
  }
};


var elementsMaskBox = document.createElement("div"),boxPup = document.createElement("div");

DialogBox_show.prototype.add_mask = function(){
	//alert(this.elScroll)
	this.setAttr(this.elementsMaskBox,{className:'w_mask',id:'w_mask'});
	this.bd.appendChild(this.elementsMaskBox);
	this.setAttr(this.elementsMaskBox.style,{height:this.elScroll+'px'});
	
};

DialogBox_show.prototype.elementsTag = function( boxWidth,HTML,s,txt ){
	
	var boxW = boxWidth == null ?  this.eWidth : boxWidth;
	this.setAttr(boxPup,{className:'w_tagPupD',id:'w_tagPupD'});
	this.a = this[0].createElement("a");
	this.a.href = 'javascript:void(0)';
	this.a.className = 'w_sub';
	this.a.onclick = function(){
		
		hidePupBox('w_tagPupD','w_mask');
	};
	this.a.innerHTML = txt;
	
	this.setAttr(boxPup.style,{width:boxW+'px'});
	
	var INNERHTML = '<div class="b"><h3 class="w_title">'+s+'</h3>'+
					'<div class="w_Contxt">'+HTML+'</div>'+
					'<div class="w_submte" id="w_submit"></div></div>';
					
	
	boxPup.innerHTML = INNERHTML;
	
	
	this.bd.appendChild(boxPup);
	
	var submitP = this[0].getElementById('w_submit');
		if (txt!=null && txt !=''){
			submitP.appendChild(this.a);
		}else{
			submitP.className = 'w_submte hide';
		}
	
	var scllW = boxPup.scrollWidth/2,scllH = boxPup.scrollHeight/2;
	this.setAttr(boxPup.style,{marginLeft:-scllW+'px',marginTop:-scllH+'px'});
	
}


DialogBox_show.prototype.info = function( boxWidth,h,s,txt ){
	this.elementsTag( boxWidth,h,s,txt );
}

DialogBox_show.prototype.setAttr = function( o,Class ){
	
	for(var k in Class){
		
		o[k] = Class[k];
		
	}
};

function hidePupBox( o,k ){
	
	var PupBox = document.getElementById( o ),ar=[];
	var elementsMaskBox = document.getElementById(k);
	var bd = document.getElementsByTagName("body")[0];
	ar.push(PupBox,elementsMaskBox);

	for(var i in ar){
		
		
		bd.removeChild(ar[i]);
		
	}
	
}

function init_img_uploader(upload_url, upload_name, upload_element, upload_status_elememt, perview_element)
{
    return new AjaxUpload(upload_element, {
        action: upload_url,
        name: upload_name,
        responseType: 'json',
        
        onSubmit: function (file, ext) {
            if (!new RegExp('(png|jpg|jpeg|gif|bmp)$', 'i').test(ext))
            {
                alert("请选择正确的图片文件");
                
                return false;
            }
			
            this.disable();
            
            if (upload_status_elememt)
            {
            	upload_status_elememt.show();
            }
        },
        
        onComplete: function (file, response) {
            this.enable();
            
			if (upload_status_elememt)
            {
            	upload_status_elememt.hide();
            }
            
            if (response.errno == '-1')
			{
            	alert(response.err);
        	}
        	else
        	{
        		if (typeof(perview_element.attr('src')) != 'undefined')
        		{
	        		perview_element.attr('src', response.rsm.preview + '?' + Math.random());
        		}
        		else
        		{
	        		perview_element.css('background-image', 'url(' + response.rsm.preview + '?' + Math.random() + ')');
        		}
            }		
        }
    });
}

function init_avatar_uploader(upload_element, upload_status_elememt, avatar_element)
{
	return init_img_uploader(G_BASE_URL + '/account/ajax/avatar_upload/', 'user_avatar', upload_element, upload_status_elememt, avatar_element);
}

function init_fileuploader(element_id, action_url)
{
	if (!document.getElementById(element_id))
	{
		return false;
	}
	
	return new _ajax_uploader.FileUploader({
		element: document.getElementById(element_id),
		action: action_url,
		debug: false
	});
}

function share_content(share_type, target_id, focus_tab, weibo_enabled)
{
	if (typeof focus_tab == 'undefined')
	{
		focus_tab = "weibo";
	}

	switch(share_type)
	{
		//请求分享内容
		case 'question' : 
			url = G_BASE_URL + "/question/ajax/question_share_txt/question_id-" + target_id;
			share_title = "分享问题";
			break;
		case 'answer' : 
			url = G_BASE_URL + "/question/ajax/answer_share_txt/answer_id-" + target_id;
			share_title = "分享回复";
			break;
		case 'topic' : 
			url = G_BASE_URL + "/topic/ajax/topic_share_txt/topic_id-" + target_id;
			share_title = "分享话题";
			break;
	}
	
	if (typeof url == 'undefined')
	{
		return false;
	}

	var title = '<a href="javascript:;" onclick="hidePupBox(\'w_tagPupD\',\'w_mask\');" class="close_ti" title="点击关闭对话框 "><em>close</em></a>' + share_title;
	
	new DialogBox_show('500', '<p style="padding: 15px 0" align="center"><img src="' + G_STATIC_URL + '/common/loading_b.gif" alt="" /></p>', title, '', function()
	{
		$('#w_tagPupD').css('marginTop', '-130px');
	});
	
	$.get(url, function(result)
	{
		if (result.errno == '1')
		{
			//判断微博绑定
			$.get(G_BASE_URL + '/account/ajax/get_weibo_bind_status/', function(weibo_result)
			{
				if (weibo_result.errno == 1)
				{
					$('.w_Contxt').html(show_share_box(weibo_enabled));
					
					$("#menu_s").find("li[rel=" + focus_tab + "]").click();

					var qq_weibo = weibo_result.rsm.qq_weibo.name;
					var sina_weibo = weibo_result.rsm.sina_weibo.name;
					
					var weibo_html = '';
					
					if (weibo_result.rsm.qq_weibo.enabled == 'Y' || weibo_result.rsm.sina_weibo.enabled == 'Y')
					{
						if (qq_weibo == null && weibo_result.rsm.qq_weibo.enabled == 'Y')
						{
							weibo_html += '<p class="sc-wb"><a title="腾讯微博"  href="'+G_BASE_URL + '/account/qq/binding/"><img src="' + G_STATIC_URL + '/common/share_tx_wb.gif">绑定腾讯微博帐号</a></p>';
						}
						
						if (sina_weibo == null && weibo_result.rsm.sina_weibo.enabled == 'Y')
						{
							weibo_html += '<p class="sc-wb"><a title="新浪微博"  href="'+G_BASE_URL + '/account/sina/binding/"><img src="' + G_STATIC_URL + '/common/icoSina.gif">绑定新浪微博帐号</a></p>';
						}
						
						if (qq_weibo == null && sina_weibo == null)
						{
							weibo_html += '<p class="p">绑定微博之后，可以方便把精彩问答分享到该微博，并可以邀请你的微博好友来回复该问题或者加入 ' + G_SITE_NAME + '</p>';
						}

						weibo_account = '';
						wb_select = '';
						
						if(sina_weibo != null || qq_weibo != null)
						{
							if (sina_weibo != null)
							{
								weibo_account += '新浪微博帐号：<a href="javascript:;">' + sina_weibo + '</a>&nbsp;&nbsp;';
								wb_select += '<label><input type="checkbox" value="3" checked="checked" name="push_sina"> 新浪微博</label>&nbsp;&nbsp;';
							}
							
							if (qq_weibo != null)
							{
								weibo_account += '腾讯微博帐号：<a href="javascript:;">' + qq_weibo + '</a>';
								wb_select += '<label><input type="checkbox" value="3" checked="checked" name="push_qq"> 腾讯微博</label>';
							}
							weibo_html += '<p class="sc-wb">已经绑定：' + weibo_account + '</p><form id="share_weibo_from" method="post" action="' + G_BASE_URL + '/account/ajax/weibo_push/"><textarea rel="weibo" name="push_message" class="txt_area" style="width:430px;"></textarea>' + wb_select + '<p class="tr"><a href="javascript:;" onclick="ajax_post($(\'#share_weibo_from\'), _pm_form_processer);  $(\'#tip_share_send\').hide();" class="set_msg">发布</a><a href="javascript:;" onclick="hidePupBox(\'w_tagPupD\',\'w_mask\');">取消</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></form>';
						}
					}
					
					$('#weibo_share').html(weibo_html);

					$("[name=model_type]").val(share_type);
					$("[name=target_id]").val(target_id);
					
					$(".txt_area[rel=weibo]").html(result.rsm.share_txt.weibo);
					$(".txt_area[rel=mail]").html(result.rsm.share_txt.mail);
					$(".txt_area[rel=message]").html(result.rsm.share_txt.message);
				}
			}, 'json');
		}
	}, 'json');

}

function show_share_box(weibo_enabled)
{
	var html = '<ul id="menu_s">';
	
	if (weibo_enabled == 'Y')
	{
		html += '<li class="cur" onclick="elementClickEvent.tabs(this); $(\'#tip_share_send\').hide();" rel="weibo" uid="0">微博分享</li>'+
				'<li onclick="elementClickEvent.tabs(this); $(\'#tip_share_send\').hide();" rel="mail" uid="1">邮件分享</li>'+
				'<li onclick="elementClickEvent.tabs(this); $(\'#tip_share_send\').hide();" rel="letter" uid="2">私信分享</li>';
	}
	else
	{
		html += '<li class="cur" onclick="elementClickEvent.tabs(this); $(\'#tip_share_send\').hide();" rel="mail" uid="0">邮件分享</li>'+
				'<li onclick="elementClickEvent.tabs(this); $(\'#tip_share_send\').hide();" rel="letter" uid="1">私信分享</li>';
	}
	
	html += '</ul>';
	
	html += '<div class="default_error_share hide" id="tip_share_send"></div>';
	
	if (weibo_enabled == 'Y')
	{
		html += '<div id="weibo_share" class="class_share"></div>';
	}

	html += '<div class="class_share hide" id="mail_share"><form id="mail_share_form" onSubmit="return false;" method="post" action="'+G_BASE_URL + '/question/ajax/send_share_email/"><input type="hidden" name="model_type" value=""/><input type="hidden" name="target_id" value=""/><ul class="txt_list">'+
			'<li><label for="inputsType_txt">收件人：</label><input type="text" name="email_address" class="txt_input"/></li>'+
			'<li><label for="inputsType_area">内容：</label><textarea rel="mail" class="txt_area" name="email_message"></textarea></li>'+
			'</ul><p class="tr"><a href="javascript:;" onclick="ajax_post($(\'#mail_share_form\'), _pm_form_processer); $(\'#tip_share_send\').hide();" class="set_msg">发送</a><a href="javascript:;" onclick="hidePupBox(\'w_tagPupD\',\'w_mask\');">取消</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></form></div>'+
			'<div class="class_share hide" id="letter_share"><form id="message_share_form" onSubmit="return false;" method="post" action="'+G_BASE_URL + '/inbox/ajax/send/click_id-share_box_close__tips_id-share_send"><ul class="txt_list">'+
			'<li><label for="userShare_txt">发给：</label><input type="text" name="recipient" class="txt_input" id="userShare_txt"/><div class="ajax_date hide"></div></li>'+
			'<li><label for="inputsType_area">内容：</label><textarea name="message" rel="message" class="txt_area"></textarea></li></ul>'+
			'<p class="tr"><a href="javascript:;" onclick="ajax_post($(\'#message_share_form\'), _pm_form_processer); $(\'#tip_share_send\').hide(); return false;" class="set_msg">发送</a><a href="javascript:;" id="share_box_close" onclick="hidePupBox(\'w_tagPupD\',\'w_mask\');">取消</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></form></div>';

	return html;
}

function htmlspecialchars(text)  
{  
    return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
}

function delete_draft(item_id, type)
{
	$.post(G_BASE_URL + '/account/ajax/delete_draft/', 'item_id=' + item_id + '&type=' + type, function (result) {
		if (result.errno != 1)
		{
			qAlert(result.err);
		}
	}, 'json');
}

function agree_show(el)
{
	el.hide();
	el.parent().find(".defa_agree").show();
	el.parent().find(".defa_oppose").show();
	el.parent().find('[name=agree_num]').show();
	if (Number(el.html()) >= 1) el.parent().find("[name=agree_user_list]").show();
}


function change_agree(el, st)
{
	if (el.attr('ajax_doing') == '1')
	{
		return;
	}
	
	el.attr('ajax_doing', '1');
	
	var this_answer = el.parent().parent();
	var alc = el.parent().find('a').first();
	var agree_num = el.parent().find('[name=agree_num]');
	var status = String(alc.attr('status'));
	var answer_id = alc.attr('name');
	var new_ag_users = new Array();

	this_answer.find('.defa_agree').removeClass("up_cur").attr("onmousemove", "aw.elems_tips(this,0);");
	this_answer.find('.defa_oppose').removeClass("down_cur").attr("onmousemove", "aw.elems_tips(this,2);");
	
	if (status == st)
	{
		alc.attr('status', 0);
		if (st == '1')
		{
			agree_num.html(Number(agree_num.html()) - 1);
			this_answer.find('a[rel=' + G_USER_ID + ']').remove();
		}
	}
	else
	{
		alc.attr('status', st);

		if (st == '1')
		{
			agree_num.html(Number(agree_num.html()) + 1);
			this_answer.find('a[rel=' + G_USER_ID + ']').remove();
			var cur_user = new Array();
			cur_user[0] = G_USER_ID;
			cur_user[1] = G_USER_NAME;
			new_ag_users.push(cur_user);
			el.addClass("up_cur").parent().find('.defa_agree').attr("onmousemove", "aw.elems_tips(this,1);");
		}
		else if (st == '-1')
		{
			if (status == '1')
			{
				agree_num.html(Number(agree_num.html()) - 1);
				this_answer.find('a[rel=' + G_USER_ID + ']').remove();
			}
			el.addClass("down_cur").parent().find('.defa_oppose').attr("onmousemove", "aw.elems_tips(this,3);");
		}
	}

	this_answer.find('[name=agee_people]').each(function (){
		var user = new Array();
		user[0] = $(this).attr('rel');
		user[1] = $(this).html();
		new_ag_users.push(user);
	});
	
	var count = 0;
	var new_aus_str = "";
	$(new_ag_users).each(function (i){
		new_aus_str += '<a href="' + G_BASE_URL + '/people/' + new_ag_users[i][0] + '" rel="' + new_ag_users[i][0] + '" onmouseover="eventsMouseM(this);" name="agee_people" class="a">' + new_ag_users[i][1] + '</a>';
		if (new_ag_users.length > ++count) new_aus_str += "、";
	});
	
	this_answer.find(".agee_people").html(new_aus_str);
	
	if (new_ag_users.length == 0)
	{
		this_answer.find("[name=agree_user_list]").hide();
	}
	else
	{
		this_answer.find("[name=agree_user_list]").show();
	}
	
	$.post(G_BASE_URL + '/question/ajax/change_vote/', "answer_id=" + answer_id + "&value=" + st, function (result) {
		if (result.errno == 1)
		{
			el.removeAttr('ajax_doing');
		}
		else if (result.errno == -1)
		{
			qAlert(result.err);
		}
	}, 'json');

	return true;
}


//问题-不感兴趣
function question_uninterested(el, question_id)
{
	el.fadeOut();
	
	$.post(G_BASE_URL + '/question/ajax/uninterested/', 'question_id=' + question_id, function (result) {
		if (result.errno != '1')
		{
			alert(result.err);
		}
	}, 'json');
}

function cancel_question_invite(el, question_id, recipients_uid)
{
	$.get(G_BASE_URL + '/question/ajax/cancel_question_invite/question_id-' + question_id + '__recipients_uid-' + recipients_uid, function (result) {
		if (result.errno == '1')
		{
			var dnums = Number($(".defa_nums").html());

			$(".defa_nums").html(--dnums);
			
			if(dnums == 0)
			{
				$(".defa_nums").hide();
			}
			
			el.parent().remove();
		}
		else
		{
			alert(result.rsm.err);
		}
	}, 'json');
}

function question_invite_delete(el, question_invite_id)
{
	$.post(G_BASE_URL + '/question/ajax/question_invite_delete/', 'question_invite_id=' + question_invite_id, function (result) {
		if (result.errno == '1')
		{
			el.parent().parent().remove();
		}
		else
		{
			alert(result.rsm.err);
		}
	}, 'json');
}

function toggle_comments(item_id, type_name)
{	
	if ($('#' + type_name + '_comments_' + item_id).css('display') == 'none')
	{
		if ($('#' + type_name + '_comments_' + item_id + ' div[name=comments_list]').html() == '')
		{
			reload_comments_list(item_id, item_id, type_name);
		}
		
		$('#' + type_name + '_comments_' + item_id).fadeIn();
	}
	else
	{
		$('#' + type_name + '_comments_' + item_id).fadeOut();
	}
}

function reload_comments_list(item_id, element_id, type_name)
{
	var _element_id = element_id;
	
	$('#' + type_name + '_comments_' + _element_id + ' div[name=comments_list]').html('<p style="padding: 10px 0" align="center"><img src="' + G_STATIC_URL + '/common/load.gif" alt="" /></p>');
	
	$.get(G_BASE_URL + '/question/ajax/get_' + type_name + '_comments/' + type_name + '_id-' + item_id, function (data) {
		$('#' + type_name + '_comments_' + _element_id + ' div[name=comments_list]').html(data);
	});
}

function header_message(message)
{
	$('<div/>').addClass('reply_div').html('<p><!--<span title="点击取消显示" class="s"></span>-->' + message + '</p>').appendTo($('#default_msg'));
}

function save_answer_comment(answer_id, save_button_el)
{
	$(save_button_el).attr('_onclick', $(save_button_el).attr('onclick')).addClass('disabled').removeAttr('onclick');
	
	ajax_post($('#answer_comments_' + answer_id + ' form'), _comments_form_processer);
}

function _comments_form_processer(result)
{
	$.each($('a.answer_comments.disabled'), function (i, e) {
		$(this).attr('onclick', $(this).attr('_onclick')).removeAttr('_onclick').removeClass('disabled');
	});
	
	if (result.errno != 1)
	{
		qAlert(result.err);
	}
	else
	{
		reload_comments_list(result.rsm.item_id, result.rsm.item_id, result.rsm.type_name);

		$('#' + result.rsm.type_name + '_comments_' + result.rsm.item_id + ' form input').val("");

		$('#' + result.rsm.type_name + '_comments_' + result.rsm.item_id + ' form').fadeOut();
	}
}

function remove_comment(el, type, comment_id)
{
	bl = el.parents('.default_com_user');
	el.parents('.default_com_u').remove();
	
	if(bl.find('ul').length == 0)
	{
		bl.parents('div .default_comment').find('form').show();
		bl.remove();
	}

	$.get(G_BASE_URL + '/question/ajax/remove_comment/type-' + type + '__comment_id-' + comment_id);
}

function insert_attach(el, attach_id, attach_tag)
{
	$(el).parents('form').find('textarea').val($(el).parents('form').find('textarea').val() + "\n[" + attach_tag + "]" + attach_id + "[/" + attach_tag + "]\n");
}